/* 封装一个指令tab */
class runner{
    constructor(){

        this.restrict   = 'AE';
        this.require    = '^?runnerList';
        this.scope      = { active: '=?' };
        this.template   = '<li ng-class="{active: active}" ng-click="show()" ng-transclude></li>';
        this.replace    = true;
        this.transclude = true;

    }

    link(scope, element, attrs, tabsetController) {
        tabsetController.addItem(scope);
        scope.$watch('active', (active) => {
            if (active) {
                tabsetController.gotOpened(scope);
            }
        });
        scope.show = () => {
            scope.active = !scope.active;
            tabsetController.gotOpened(scope);
        };

        element.on('click', this.click)
    }

    click() {
        var height, second, siblings;

        second   = $(this).find('.nav-second-level');
        // siblings = $(this).siblings().find('.nav-second-level');

        if(second.length==0) return false;

        if (!$(this).hasClass('active')) {
            // siblings.removeClass('collapsing').removeAttr('style');
            second.addClass('collapsing');
            height = second[0].scrollHeight;
            second.css({ height: height});
        } else {
            second.removeAttr('style');

            setTimeout( () => second.removeClass('collapsing'), 350)
        }
    }
}

export default runner;